<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入主题样式 -->
<link href="../themes/bootstrap/easyui.css" rel="stylesheet"></link>
<!-- 引入图标样式 -->
<link href="../themes/icon.css" rel="stylesheet"></link>
<!-- 引入jquer -->
<script type="text/javascript" src="../js/jquery-1.9.1.js"></script>
<!-- 引入easyui.js -->
<script type="text/javascript" src="../js/jquery.easyui.min.js"></script>
<!-- 引入本地语言 -->
<script type="text/javascript" src="../js/easyui-lang-zh_CN.js"></script>
<title>Insert title here</title>
<style type="text/css">
.radioSpan {
	position: relative;
	border: 1px solid #95B8E7;
	background-color: #fff;
	vertical-align: middle;
	display: inline-block;
	overflow: hidden;
	white-space: nowrap;
	margin: 0;
	padding: 0;
	-moz-border-radius: 5px 5px 5px 5px;
	-webkit-border-radius: 5px 5px 5px 5px;
	border-radius: 5px 5px 5px 5px;
	display: block;
}
</style>
<script type="text/javascript">
	$(function(){
	//日历不可编辑
	 $(".datebox :text").attr("readonly","readonly"); 
	//限制输入字数
	 $(":text").keydown(function(){
                $.each($(":text"),function(i){
                    if($(":text")[i].value.length>30){
                        $(":text")[i].value = '';//从新设置input输入框的值
                        alert("错误，输入超出30个字符");
                    }
                })
            })
	$('#gstate').validatebox({ 
	required:true 
	});
		//配置搜索框
	$('#search').searchbox({
	//在用户按下搜索按钮或回车键的时候调用searcher函数
		searcher:function(value,name){
			var uname = value;
			$('#orderShow').datagrid('reload',{
			//搜索框的值，传入后台
				searchname:uname
			}) 
		}
	});
	//配置提交配置货物表单
		$("#addGoods").form({
			url:'${pageContext.request.contextPath}/addGoods',
			success:function(data){
				 if(data == "1"){
					$('#adGoods').dialog('close');
					$("#addGoods").form('clear');
					$.messager.alert('我的消息','提交成功','info',function(){
						$("#orderShow").datagrid('unselectAll');
						$('#orderShow').datagrid('reload');
						$("#adgo1").prop("disabled", false);
					});
				}else if(data == "-1"){
              $.messager.alert('我的消息','该订单已经存在货物配送列表中','info',function(){
						$('#orderShow').datagrid('reload');
						$('#adGoods').dialog('close');
						$("#addGoods").form('clear');
						$("#orderShow").datagrid('unselectAll');
					});	
            
            }
				else{
						$.messager.alert('我的消息','添加失败','info',function(){
						$('#orderShow').datagrid('reload');
						$('#adGoods').dialog('close');
						$("#addGoods").form('clear');
						$("#orderShow").datagrid('unselectAll');
					});	
				}
				}
		})
		//配置修改表单
		$("#upOrder").form({
			url:'${pageContext.request.contextPath}/updateOrder',
			success:function(data){
				 if(data=="1"){
					$('#updateOrder').dialog('close');
					$("#upOrder").form('clear');
					$.messager.alert('我的消息','更新成功','info',function(){
					$("#orderShow").datagrid('unselectAll');
						$('#orderShow').datagrid('reload');
						$("#upgo").prop("disabled", false);
					});
				}else{
						$.messager.alert('我的消息','更新失败','info',function(){
						$('#orderShow').datagrid('reload');
						$('#updateOrder').dialog('close');
						$("#upOrder").form('clear');
						$("#orderShow").datagrid('unselectAll');
					});	
				}
				}
		})
	//增加表单
	$("#adOrder").form({
		url:'${pageContext.request.contextPath}/addOrder',
			success:function(data){
				 if(data=="1"){
					$('#addOrder').dialog('close');
					$("#adOrder").form('clear');
					$.messager.alert('我的消息','添加成功','info',function(){
						$('#orderShow').datagrid('reload');
						$("#adgo").prop("disabled", false);
					});
				 }else{
						$.messager.alert('我的消息','增加失败','info',function(){
						$('#orderShow').datagrid('reload');
						$('#addOrder').dialog('close');
						$("#adOrder").form('clear');
						$("#orderShow").datagrid('unselectAll');
					});	
				}
				 }
	})
	//删除表单
	$("#deleteOrder").form({
		url:'${pageContext.request.contextPath}/deleteOrder',
			success:function(data){
				 if(data=="1"){
					$.messager.alert('我的消息','删除成功成功','info',function(){
						$('#orderShow').datagrid('reload');
					});
				 }
				 }
	})
	//关闭对话框	
$("#closed1").click(function(){
	$("#updateOrder").dialog('close');
})
$("#closed2").click(function(){
	$("#addOrder").dialog('close');
})
$("#closed3").click(function(){
	$("#adGoods").dialog('close');
})
// 对话框默认为关闭
	$("#addOrder").dialog('close');
	$("#updateOrder").dialog('close');
	$("#adGoods").dialog('close');
	
		$('#orderShow').datagrid({    
			    url:'${pageContext.request.contextPath}/searchOrder',    
			     idField: 'oid',
			    columns:[[ 
					{field:'oid',checkbox:true,width:100},
                    {field:'oname',title:'订单名称',width:100},
                    {field:'otime',title:'下单时间',width:100,align:'right'},
                    {field:'opass',title:'是否通过审核',width:100},
                    {field:'oaddress',title:'订单地址',width:100},
                    {field:'opay',title:'支付方式',width:100},
                    {field:'oisok',title:'收货(1是被收货)',width:100},
                    {field:'ofinishtime',title:'签收时间',width:100},
			    ]],
			    //如果为true，则在DataGrid控件底部显示 分页 工具栏。
			    pagination:true,
			    striped:true,
			    toolbar: [{
					iconCls: 'icon-add',
					text:'新增',
					handler: function(){
								$("#addOrder").dialog('open');
								
						}
				},'-',{
					iconCls: 'icon-remove',
					text:'删除',
					handler: function(){
							var ord = $("#orderShow").datagrid('getSelections');
							
							 if (ord.length > 0) {
                         $.messager.confirm("提示", "你确定要删除吗?", function (r) {
                             if (r) {
                          /*        var ids = [];
                                 for (var i = 0; i < ord.length; i++) {
                                     ids.push(ord[i].oid);
                                 }*/$("#deleteOrder").form('submit');
                                
                             
                             }
                         });
                     }
                     else {
                         $.messager.alert("提示", "请选择要删除的行", "error");
                     }
                 }
					
				},'-',{
					iconCls: 'icon-edit',
					text:'修改',
					handler: function(){
							
							var ord = $("#orderShow").datagrid('getSelections');
							if(ord.length != 1){
							$.messager.confirm('提示','修改只能选择一条数据',function(){
									$("#orderShow").datagrid('unselectAll');
							})
							
							}else{
									$("#updateOrder").dialog('open');
									var order = ord[0];
									 $('#upOrder').form('load',order);
							}
					}
				},'-',{
					iconCls: 'icon-ok',
					text:'添加到货物配送',
					handler: function(){
							
							var ord = $("#orderShow").datagrid('getSelections');
							
							if(ord.length != 1){
							$.messager.confirm('提示','配送单填写只能选择一条数据',function(){
									$("#orderShow").datagrid('unselectAll');
							})
							
							}else{
									$("#adGoods").dialog('open');
									var order = ord[0];
							
									 $('#addGoods').form('load',
order
									 );
							}
					}
				}
				]
				,
				striped:true,
				rownumbers:true
			}); 
	
	})
	//配置更新表单提交事件
	function updataForm() {
		  	var d1 = document.getElementsByName("otime")
            var d2 = document.getElementsByName("ofinishtime")
            var now = (new Date()).toLocaleDateString()
            var day1=new Date(d1[0].value.replace(/[^\/\d]+/g,"/")+",0:0:0");
            var day2=new Date(d2[0].value.replace(/[^\/\d]+/g,"/")+",0:0:0");
            var day3=new Date(now.replace(/[^\/\d]+/g,"/")+",0:0:0");
            day1.setMonth(day1.getMonth() + 1);
            if (day2 > day1) {
              $.messager.alert('我的消息','日期错误,两次日期选择不能超过一个月','info',function(){
					$("#updateOrder").dialog('reload');
						
					});	
            }else if(day2 < day1.setMonth(day1.getMonth() -1)){
                   $.messager.alert('我的消息','日期错误,结单的日期不能在下单之前','info',function(){
					$("#updateOrder").dialog('reload');
						
					});	
            }else if(day2 < day3){
              $.messager.alert('我的消息','过去的日子不能再回去了不是吗？所以结单时间请选择今天以后的时间','info',function(){
					$("#addOrder").dialog('reload');
						
					});	
            
            }
            else{
		$("#upOrder").form('submit');
		$("#upgo").prop("disabled", true);
		}
	}
	//配置添加表单提交事件
	function addForm() {
			var d1 = document.getElementsByName("time")
            var d2 = document.getElementsByName("finishtime")
            var now = (new Date()).toLocaleDateString();
            var day1=new Date(d1[0].value.replace(/[^\/\d]+/g,"/")+",0:0:0");
            var day2=new Date(d2[0].value.replace(/[^\/\d]+/g,"/")+",0:0:0");
            var day3=new Date(now.replace(/[^\/\d]+/g,"/")+",0:0:0");
            if (day2 > day1.setMonth(day1.getMonth() + 1)) {
              $.messager.alert('我的消息','日期错误,两次日期选择不能超过一个月','info',function(){
					$("#addOrder").dialog('reload');
						
					});	
			}else if(day2 < day1.setMonth(day1.getMonth() -1)){
                $.messager.alert('我的消息','日期错误,结单的日期不能在下单之前','info',function(){
					$("#addOrder").dialog('reload');
						
					});	
            }else if(day2 < day3){
              $.messager.alert('我的消息','过去的日子不能再回去了不是吗？所以结单时间请选择今天以后的时间','info',function(){
					$("#addOrder").dialog('reload');
						
					});	
            
            }
			else{	
		$("#adOrder").form('submit');
		$("#adgo").prop("disabled", true);
		}
	}
	//配置货物配送添加表单提交事件
	function adForm() {
		$("#addGoods").form('submit');
		$("#adgo1").prop("disabled", true);
	}
	function validPass(){
			var pass = document.getElementsByName("pass")
			alert(pass[0].value)
			if(pass[0].value == '否'&&pass[1].value == '是')
			alert(1232423)
	}
	        //限制输入字数
    function controlLen(){
            //获取input输入框元素
            var input = $(":text");
            $.each(input,function(i){
                if(input[i].value.length>100){
                    input[i].value = '';//从新设置input输入框的值
                    alert("输入溢出，请重新输入");
                }
            })
        }

	//显示时间
        setInterval(function() {
            var now = (new Date()).toLocaleString();
            $('#current-time').text(now);
        }, 1000);
        

</script>
</head>
<body style="background:url(../images/44.jpg);width: 100%; height: 100%">

	
				<input id="search" class="easyui-searchbox" data-options="prompt:'输入名称查询信息',width:150">
			
	
	<form id="deleteOrder" method="post">
		<table id="orderShow"></table>
	</form>
	<div id="updateOrder" class="easyui-dialog" title="修改信息"
		style="width: 400px; height: 430px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true">
		<form id="upOrder" method="post">
			<div style="margin-bottom: 20px;display: none;">
				<span>订单id</span> <input class="easyui-textbox"  name="oid"
					style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>订单名称</span> <input class="easyui-textbox"  type="text" name="oname"
					style="width: 100%" data-options=""  onkeydown="controlLen();">
			</div>
			<div style="margin-bottom: 20px">
				<span>下单时间</span> <input type="text" name="otime" size="20"
					id="otime" class="easyui-datebox" style="width: 100%; height: 30px" />

			</div>
			<div style="margin-bottom: 20px">
				<span class="radioSpan">订单是否通过 <input type="radio"
					name="opass" value="是">是</input> <input type="radio" name="opass"
					value="否">否</input>
				</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>订单地址</span> <input class="easyui-textbox" name="oaddress"
					type="text"style="width: 100%" data-options="" onkeydown="controlLen();">
			</div>
			<div style="margin-bottom: 20px">
				<span class="radioSpan">订单是否被签收 <input type="radio"
					name="oisok" value="1">是</input> <input type="radio" name="oisok"
					value="0">否</input>
				</span>
			</div>


			<div style="margin-bottom: 20px">
				<span>支付方式</span> <select id="cc" 
					name="opay">
					<option value="支付宝">支付宝</option>
					<option value="微信支付">微信支付</option>
					<option value="QQ钱包">QQ钱包</option>
					<option value="网银支付">网银支付</option>
					<option value="网易钱包">网易钱包</option>
				</select>
			</div>

			<div style="margin-bottom: 20px">
				<span>订单结单时间</span> <input type="text" name="ofinishtime" size="20"
					id="odate" class="easyui-datebox" style="width: 100%; height: 30px" />
			</div>
			<div style="text-align: center; padding: 5px 0">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="updataForm()" style="width: 80px"id="upgo" >提交</a> <a
					href="javascript:void(0)" class="easyui-linkbutton" id="closed1"
					onclick="close()" style="width: 80px">关闭</a>
			</div>
		</form>

	</div>

	<!-- 增加订单 -->
	<div id="addOrder" class="easyui-dialog" title="增加订单"
		style="width: 400px; height: 430px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true">
		<form id="adOrder" method="post">
			<div style="margin-bottom: 20px; display: none;">
				<span>订单id</span> <input class="easyui-textbox" name="id"
					style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>订单名称</span> <input class="easyui-textbox" type="text" name="name"
					style="width: 100%" data-options="" onkeydown="controlLen();">
			</div>
			<div style="margin-bottom: 20px">
				<span>下单时间</span> <input type="text" name="time" size="20"
					id="odate" class="easyui-datebox" style="width: 100%; height: 30px" />
			</div>
			<div style="margin-bottom: 20px">

				<span class="radioSpan">订单是否通过 <input type="radio"
					name="pass" value="是">是</input> <input type="radio" name="pass"
					value="否">否</input>
				</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>订单地址</span> <input class="easyui-textbox" type="text"name="address"
					style="width: 100%" data-options="" onkeydown="controlLen();">
			</div>
			<div style="margin-bottom: 20px">

				<span class="radioSpan">订单是否被签收 <input type="radio"
					name="isok" value="1">是 <input type="radio" name="isok"
					value="0">否
				</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>支付方式</span> <select id="cc"  name="pay">
					<option value="支付宝">支付宝</option>
					<option value="微信支付">微信支付</option>
					<option value="QQ钱包">QQ钱包</option>
					<option value="网银支付">网银支付</option>
				</select>
			</div>
			<div style="margin-bottom: 20px">
				<span>订单结单时间</span> <input type="text" name="finishtime" size="20"
					class="easyui-datebox" style="width: 100%; height: 30px"  />
			</div>
			<div style="text-align: center; padding: 5px 0">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="addForm()" style="width: 80px" id="adgo" onclick="date()">提交</a> <a
					href="javascript:void(0)" class="easyui-linkbutton" id="closed2"
					onclick="close()" style="width: 80px">关闭</a>
			</div>
		</form>

	</div>
	
		<!-- 填写货物配送单 -->
	<div id="adGoods" class="easyui-dialog" title="货物配送单"
		style="width: 400px; height: 430px;"
		data-options="iconCls:'icon-save',resizable:true,modal:true">
	<form method="post" id="addGoods">
			<div style="margin-bottom: 20px;display: none; ">
				<span>订单id</span> <input class="easyui-textbox" name="oid"
					style="width: 100%;">
			</div>
			<div style="margin-bottom: 20px">
				<span>快递名称</span>
				<select id="cc" name="gname">
					<option value="顺丰快递">顺丰快递</option>
					<option value=中通快递">中通快递</option>
					<option value="圆通快递">圆通快递</option>
					<option value="申通快递">申通快递</option>
					<option value="EMS">EMS</option>
					<option value="韵达快递">韵达快递</option>
					<option value="汇通快递">汇通快递</option>
				</select>
			</div>
			<div style="margin-bottom: 20px">
				<span>快递揽件时间</span> <input type="text" name="gtime" size="20"
					id="odate" class="easyui-datetimebox" style="width: 100%; height: 30px" />
			</div>
			<div style="margin-bottom: 20px">

				<span class="radioSpan">送货状态（自行填写）<input class="easyui-textbox" name="gstate" id="gstate"
					type="text"	style="width: 100%" data-options="" onkeydown="controlLen();">
				</span>
			</div>
			<div style="margin-bottom: 20px">
				<span>快递地址</span> <input class="easyui-textbox" name="gaddress"
					type="text"	style="width: 100%" data-options="" onkeydown="controlLen();">
			</div>
					<div style="text-align: center; padding: 5px 0">
				<a href="javascript:void(0)" class="easyui-linkbutton"
					onclick="adForm()" style="width: 80px" id="adgo1">提交</a> <a
					href="javascript:void(0)" class="easyui-linkbutton" id="closed3"
					onclick="close()" style="width: 80px">关闭</a>
			</div>
		</form>
	</div>
	<div id="current-time"></div>
</body>
</html>